package zhihuilan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import zhihuilan.dto.MyCircleDto;
import zhihuilan.dto.WxMiniPageDto;
import zhihuilan.entity.MyAcquisitionMsgExtra;
import zhihuilan.entity.MyCircleCollection;

import java.util.List;

@Mapper
public interface MyCircleCollectionMapper extends BaseMapper<MyCircleCollection> {

    @Select({" <script>  select b.*,a.create_time as tid,c.headimgurl as staff_logo,c.logo as staff_headimgurl,c.title as staff_title,c.lat as staff_lat,c.lng staff_lng,c.address as staff_address,c.address1 as staff_address1,c.address2 as staff_address2,c.region as staff_region\n" +
            "    from my_circle_collection a right JOIN my_circle b on a.pid = b.id left JOIN my_staff c on b.staff_id = c.id \n" +
            " where b.status = 1 and a.staff_id =#{staffId} \n" +
            " <when test='districtid1 != null and districtid1 != \"\"'> " +
            "  and c.districtid1 =#{districtid1} \n" +
            " </when> " +
            " <when test='districtid2 != null and districtid2 != \"\"'> " +
            "  and c.districtid2 =#{districtid2} \n" +
            " </when> " +
            " order by a.create_time desc LIMIT #{page},#{pageSize} " +
            " </script>"})
    List<MyCircleDto> selectPageListToCircle(@Param("page") Long page, @Param("pageSize") Long pageSize, @Param("staffId") Integer staffId,@Param("districtid1") String districtid1,@Param("districtid2") String districtid2);


    @Select({" <script>  select count(b.id) as cnt " +
            "    from my_circle_collection a right JOIN my_circle b on a.pid = b.id left JOIN my_staff c on b.staff_id = c.id \n" +
            " where b.status = 1 and a.staff_id =#{staffId} \n" +
            " <when test='districtid1 != null and districtid1 != \"\"'> " +
            "  and c.districtid1 =#{districtid1} \n" +
            " </when> " +
            " <when test='districtid2 != null and districtid2 != \"\"'> " +
            "  and c.districtid2 =#{districtid2} \n" +
            " </when> " +
            " order by a.create_time desc " +
            " </script>"})
    Long selectCountToCircle(@Param("staffId") Integer staffId,@Param("pid") Integer pid,@Param("districtid1") String districtid1,@Param("districtid2") String districtid2);
}
